home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / c / xw2.000 / xw2 / xw / csource / xbcom.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-11  |  8.3 KB  |  301 lines

  1.  
  2.  
  3. #include "xbw.h"
  4.  
  5.  
  6. /* ================ Metafile-Interface ================================ */
  7.  
  8. char
  9.   XbWVSy_SysPath[60];
  10. int
  11.   XbWVIDEO_XA,
  12.   XbWVIDEO_XB,
  13.   XbWVIDEO_YA,
  14.   XbWVIDEO_YB;
  15.  
  16. /* ---------------- Interface ----------------------------------------- */
  17.  
  18.  
  19. char *XbWFMx_MyStrUpr(char*sstr){
  20.   /*{{{  */
  21.   int ll;
  22.   for (ll=0;sstr[ll]!=0;ll++){
  23.     sstr[ll]&=0xDF;
  24.     };
  25.   return(sstr);
  26.   };
  27.   /*}}}  */
  28. int XbWFMx_MyStrICmp(char *sstra,char*sstrb){
  29.   /*{{{  */
  30.   char sstr1[200],sstr2[200];
  31.   strcpy(sstr1,sstra);
  32.   strcpy(sstr2,sstrb);
  33.   XbWFMx_MyStrUpr(sstr1);XbWFMx_MyStrUpr(sstr2);
  34.   return(strcmp(sstr1,sstr2));
  35.   };
  36.   
  37.   /*}}}  */
  38.  
  39. #define VarDataMaxNames 5
  40.  
  41. FILE
  42.   *XbWFMx_MFXFile;
  43. char
  44.   XbWVMx_MFXFilName[80],
  45.   XbWFMx_MFXFilezeile[255];
  46. int
  47.   XbWVMx_MFXFilZlNr,
  48.   XbWVMx_AktName,
  49.   XbWVMx_ReadErr = 0;
  50. int
  51.   XbWVIf_Debug = 0;
  52.  
  53. char
  54.   XbWFMx_FStrNames[VarDataMaxNames][200];
  55.  
  56. char *XbWFMx_GetLine(void){
  57.   XbWVMx_MFXFilZlNr++;
  58.   return(fgets(XbWFMx_MFXFilezeile,253,XbWFMx_MFXFile));
  59.   };
  60.  
  61. /*{{{  XbWFMx_RdSet(       ****/
  62. int  XbWFMx_RdSet(
  63.             char *filename,
  64.             char *datensatzname){
  65.   int ll;
  66.   unsigned char ende;
  67.   int gefund;
  68.   char namestr[255];
  69.   XbWVMx_MFXFilZlNr = 0;
  70.   for (ll=0;ll<VarDataMaxNames;ll++){
  71.     strcpy(XbWFMx_FStrNames[ll],"\0");
  72.     };
  73.   strcpy(XbWVMx_MFXFilName,filename);
  74.   gefund = 0;
  75.   XbWVMx_ReadErr = 0;
  76.   if ((XbWFMx_MFXFile = XbWSSy_fopen(filename,"r")) == NULL) {
  77.     return(XbWDMx_OpnErr);
  78.     };
  79.   ende = 0;
  80.   while (!ende) {
  81.     if (XbWFMx_GetLine() == NULL) {
  82.       ende = 1;}
  83.     else {
  84.       if (strstr(XbWFMx_MFXFilezeile,"\\VarStructContents{") != NULL) {
  85.         if (XbWFMx_GetLine() == NULL) {
  86.           return(XbWDMx_EofGrp);
  87.           }
  88.         else {
  89.           if (
  90.                 (strstr(XbWFMx_MFXFilezeile,"{") != NULL) &
  91.                 (strstr(XbWFMx_MFXFilezeile,"}") != NULL)
  92.              ) {
  93.             strncpy(namestr,strstr(XbWFMx_MFXFilezeile,"{")+1,250);
  94.             strcpy(strstr(namestr,"}"),"\0");;
  95.             if ((strcmp(namestr,datensatzname)==0)|(strcmp(datensatzname,"*")==0)) {
  96.               ende = 1;
  97.               gefund = 1;
  98.               }
  99.             else {
  100.               if (XbWVMx_AktName < VarDataMaxNames) {
  101.                 strcpy(XbWFMx_FStrNames[XbWVMx_AktName],namestr);
  102.                 };
  103.               XbWVMx_AktName++;
  104.               };
  105.             };
  106.           };
  107.         };
  108.       };
  109.     };
  110.   if ((gefund == 0) & (XbWVIf_Debug == 1)) {
  111.     printf("ERROR in VarDataGet...\n");
  112.     printf("\nCannot find structure %s in file %s\n",datensatzname,filename);
  113.     printf("the following structures could be found (the first five only):\n");
  114.     for (ll=0;ll<5;ll++){
  115.       printf("%s\n",XbWFMx_FStrNames[ll]);
  116.       };
  117.     printf("Sorry...\n");
  118.     return(XbWDMx_DGrpNF);
  119.     };
  120.   return(XbWDMx_RGok);
  121.   };
  122. /*}}}  */
  123. /*{{{  XbWFMx_GetInt(      ****/
  124. int  XbWFMx_GetInt(int *variable){
  125.   char sstr[255];
  126.   XbWFMx_GetLine();
  127.   while (*(char *)XbWFTb_PckTxt(XbWFMx_MFXFilezeile) == '%') {
  128.     if (feof(XbWFMx_MFXFile)){ return(XbWDMx_EndOfF);};
  129.     XbWFMx_GetLine();
  130.     };
  131.   if (*(char *)XbWFTb_PckTxt(XbWFMx_MFXFilezeile) != 'i') {
  132.     if (strstr(XbWFMx_MFXFilezeile,"\\EndOfVarStructure;") != NULL) {
  133.       if (XbWVIf_Debug == 1) {
  134.         printf("ERROR in VarDataGet...\n");
  135.         printf("Sorry, but I cannot find your integer because end of group\n");
  136.         printf("actual File: %s\n",XbWVMx_MFXFilName);
  137.         printf("actual line: %s\n",XbWFMx_MFXFilezeile);
  138.         printf("    line no: %d\n",XbWVMx_MFXFilZlNr);
  139.         };
  140.       return(XbWDMx_RIntEg);
  141.       }
  142.     else {
  143.       if (XbWVIf_Debug == 1) {
  144.         printf("ERROR in VarDataGet...\n");
  145.         printf("Sorry, but I cannot find your integer\n");
  146.         printf("actual File: %s\n",XbWVMx_MFXFilName);
  147.         printf("actual line: %s\n",XbWFMx_MFXFilezeile);
  148.         printf("    line no: %d\n",XbWVMx_MFXFilZlNr);
  149.         };
  150.       return(XbWDMx_RIFnoI);
  151.       };
  152.     }
  153.   else {
  154.     strncpy(sstr,strstr(XbWFMx_MFXFilezeile,"i")+1,255);
  155.     *(char *)strstr(sstr,",") = 0;
  156.     *variable = atoi((char *)XbWFTb_PckTxt(sstr));
  157.     return(XbWDMx_RDok);
  158.     };
  159.   };
  160. /*}}}  */
  161. /*{{{  XbWFMx_GetDbl(      ****/
  162. int  XbWFMx_GetDbl(double *variable){
  163.   char sstr[255];
  164.   XbWFMx_GetLine();
  165.   while (*(char *)XbWFTb_PckTxt(XbWFMx_MFXFilezeile) == '%') {
  166.     if (feof(XbWFMx_MFXFile)){ return(XbWDMx_EndOfF);};
  167.     XbWFMx_GetLine();
  168.     };
  169.   if (*((char *)XbWFTb_PckTxt(XbWFMx_MFXFilezeile)) != '{') {
  170.     if (strstr(XbWFMx_MFXFilezeile,"\\EndOfVarStructure;") != NULL) {
  171.       if (XbWVIf_Debug == 1) {
  172.         printf("ERROR in VarDataGet...\n");
  173.         printf("Sorry, but I cannot find your double because end of group\n");
  174.         printf("actual File: %s\n",XbWVMx_MFXFilName);
  175.         printf("actual line: %s\n",XbWFMx_MFXFilezeile);
  176.         printf("    line no: %d\n",XbWVMx_MFXFilZlNr);
  177.         };
  178.       return(XbWDMx_RDblEg);
  179.       }
  180.     else {
  181.       if (XbWVIf_Debug == 1) {
  182.         printf("ERROR in VarDataGet...\n");
  183.         printf("Sorry, but I cannot find your double\n");
  184.         printf("actual File: %s\n",XbWVMx_MFXFilName);
  185.         printf("actual line: %s\n",XbWFMx_MFXFilezeile);
  186.         printf("    line no: %d\n",XbWVMx_MFXFilZlNr);
  187.         };
  188.       return(XbWDMx_RDFnoD);
  189.       };
  190.     }
  191.   else {
  192.     strncpy(sstr,strstr(XbWFMx_MFXFilezeile,"{")+1,255);
  193.     if (strstr(sstr,"}") != NULL) {
  194.       *(char *)strstr(sstr,"}") = 0;
  195.       }
  196.     else {return(XbWDMx_MissRP);};
  197.     *variable = atof((char *)XbWFTb_PckTxt(sstr));
  198.     return(XbWDMx_RDok);
  199.     };
  200.   };
  201. /*}}}  */
  202. /*{{{  XbWFMx_GetStr(      ****/
  203. int  XbWFMx_GetStr(char *variable){
  204.   char sstr[255];
  205.   XbWFMx_GetLine();
  206.   while (*(char *)XbWFTb_PckTxt(XbWFMx_MFXFilezeile) == '%') {
  207.     if (feof(XbWFMx_MFXFile)){ return(XbWDMx_EndOfF);};
  208.     XbWFMx_GetLine();
  209.     };
  210.   if (*((char *)XbWFTb_PckTxt(XbWFMx_MFXFilezeile)) != '{') {
  211.     if (strstr(XbWFMx_MFXFilezeile,"\\EndOfVarStructure;") != NULL) {
  212.       if (XbWVIf_Debug == 1) {
  213.         printf("ERROR in VarDataGet...\n");
  214.         printf("Sorry, but I cannot find your string because end of group\n");
  215.         printf("actual File: %s\n",XbWVMx_MFXFilName);
  216.         printf("actual line: %s\n",XbWFMx_MFXFilezeile);
  217.         printf("    line no: %d\n",XbWVMx_MFXFilZlNr);
  218.         };
  219.       return(XbWDMx_RStrEg);
  220.       }
  221.     else {
  222.       if (XbWVIf_Debug == 1) {
  223.         printf("ERROR in VarDataGet...\n");
  224.         printf("Sorry, but I cannot find your string\n");
  225.         printf("actual File: %s\n",XbWVMx_MFXFilName);
  226.         printf("actual line: %s\n",XbWFMx_MFXFilezeile);
  227.         printf("    line no: %d\n",XbWVMx_MFXFilZlNr);
  228.         };
  229.       return(XbWDMx_RSFnoS);
  230.       };
  231.     }
  232.   else {
  233.     strncpy(sstr,strstr(XbWFMx_MFXFilezeile,"{")+1,253);
  234.     sstr[253]=0;
  235.     if (strstr(sstr,"}") != NULL) {
  236.       *(char *)strstr(sstr,"}") = 0;
  237.       }
  238.     else {return(XbWDMx_MissRP);};
  239.     strcpy(sstr,(char *)XbWFTb_PckTxt(sstr));
  240.     strcpy(variable,sstr);
  241.     return(XbWDMx_RDok);
  242.     };
  243.   };
  244. /*}}}  */
  245. /*{{{  XbWFMx_WrSet(       ****/
  246. int  XbWFMx_WrSet(
  247.   /*{{{  */
  248.             char *filename,
  249.             char *datensatzname,
  250.             int mode){
  251.   if (mode == 1) {
  252.     XbWFMx_MFXFile = XbWSSy_fopen(filename,"at");
  253.     if (XbWFMx_MFXFile == NULL) {
  254.       printf("ERROR in XbWSSy_fopen(%s,%d)\n",filename,mode);
  255.       return(XbWDMx_NoApnd);
  256.       };
  257.     }
  258.   else {
  259.   
  260.     XbWFMx_MFXFile = XbWSSy_fopen(filename,"wt");
  261.     if (XbWFMx_MFXFile == NULL) {
  262.       printf("ERROR in XbWSSy_fopen(%s,%d)\n",filename,mode);
  263.       return(XbWDMx_OpnErr);
  264.       };
  265.     };
  266.   fputs("\\VarStructContents{\n",XbWFMx_MFXFile);
  267.   fputs(" {",XbWFMx_MFXFile);
  268.   fputs(datensatzname,XbWFMx_MFXFile);
  269.   fputs("}};\n",XbWFMx_MFXFile);
  270.   return(XbWDMx_WFok);
  271.   };
  272.   /*}}}  */
  273. /*}}}  */
  274. /*{{{  XbWFMx_PutInt(      ****/
  275. void  XbWFMx_PutInt(int variable, char *com){
  276.   fprintf(XbWFMx_MFXFile," i%d, %s\n",variable, com);};
  277. /*}}}  */
  278. /*{{{  XbWFMx_PutDbl(      ****/
  279. void  XbWFMx_PutDbl(double variable, char *com){
  280.   fprintf(XbWFMx_MFXFile," {%20.7f}, %s\n",variable, com);};
  281. /*}}}  */
  282. /*{{{  XbWFMx_PutStr(      ****/
  283. void  XbWFMx_PutStr(char *variable, char *com){
  284.   if (variable == NULL) {
  285.     fprintf(XbWFMx_MFXFile," {(null)}, %s\n", com);
  286.     }
  287.   else {
  288.     fprintf(XbWFMx_MFXFile," {%s}, %s\n",variable, com);
  289.     };
  290.   };
  291. /*}}}  */
  292. /*{{{  XbWFMx_EndSet(      ****/
  293. void  XbWFMx_EndSet(void){
  294.   fputs("\\EndOfVarStructure;\n",XbWFMx_MFXFile);};
  295. /*}}}  */
  296. /*{{{  XbWFMx_Close(       ****/
  297. void  XbWFMx_Close(void){
  298.   fclose(XbWFMx_MFXFile);};
  299. /*}}}  */
  300.  
  301.